<%@ page language="java" pageEncoding="UTF-8"%>
<%@include file="/pc/jsp/common/common.jsp"%>
<%@ page language="java" import="com.limao.DBDataClass.CrowdVRHomeClass"%>
<%@ page language="java" import="com.limao.DBDataClass.CrowdUserAuthClass"%>

<%
 String userid=(String)CacheClass.isLogin(request,response);
 if(CacheClass.getIntValue(userid)==0)
 {
 	out.println("<script language='JavaScript'>alert('您还没有登陆！');location.href='';</script>"); //后退并刷新
 	return;
 } 
 
 CrowdUserAuthClass user= WebFunction.getUserInfo(request,response);
 if(user==null)
 {
	 out.println("<script language='JavaScript'>alert('用户不存在，或被平台禁用，请联系客服！');window.history.back(-1);</script>");
	 return;
 } 
  if(CacheClass.getIntValue(user.isvruser)==0)
 {
	 out.println("<script language='JavaScript'>alert('用户无些权限！');window.history.back(-1);</script>");
	 return;
 }
 
CrowdVRHomeClass obj= WebFunction.getVrHomeInfo(request,response);
 if(obj==null)
 {
	 out.println("<script language='JavaScript'>alert('交易公司不存在，或平台已中止与供公司合作，暂不开放提单交易服务！');window.history.back(-1);</script>");
	 return;
 }
 
  int maxcashrmb=CacheClass.getIntValue(CacheClass.getSYS_BaseDataCacheManager().Load_Param("maxcashrmb").trim());
  
 %>
 
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <title>资金转入期指投资</title>
    <style>
        body{
            width: 100%;
            height: 100%;
            background: #fff;
        }
    </style>
</head>
</body ontouchstart="">
<div class="c3 f25 tc jz pr zijinTop">
    资金转入期指投资 <span class="db pa c3 cursor fw700 closeBtn" id="close-x">&times;</span>
</div>
<div class="w100 jz" style="background: #f3f3f3">
    <section class="saveMoneyNotice w100 bcf of">
        <div class="clearfix of jz">
            <img src="pc/images/trumpet.png" class="db fl">
            <p class="fr c6 f12 mgl10 lh18">
                您为合作方[七彩云购]用户。转入资金将从您的七彩云购账户转至市场
                账户，以便投资。
            </p>
        </div>
    </section>
    <section class="saveMoneyBlock w100 of c3">
        <div class="saveMoneyDiv jz clearfix of" style="display:none">
            <label class="f16">资金类型</label>
            <input type="hidden" id="vrid" value="<%=obj.vrid%>"/>
            <input type="radio" name="moneyKind"  checked="checked" id="moneyKind1" value="1" style="margin-left: 6%;"/>
            <label for="moneyKind1" class="f16">抵押金</label>
            <%if(CacheClass.getIntValue(obj.iscommon)==1){ %>
            <input type="radio" name="moneyKind" id="moneyKind2" value="0" style="margin-left: 6%;"/>
            <label for="moneyKind2" class="f16">普通余额</label>
            <%} %>
        </div>
        <div class="baitiaoLineMoney">
            <p class="w100" style="background: #E7E7E7"></p>
            <p class="w100" style="background: #FFFFFF"></p>
        </div>
        <div class="saveMoneyDiv jz clearfix of">
            <label for="money" class="f16">转入金额</label>
            <input type="number" name="" placeholder="" id="money" onblur="changermb();" onkeyup="value=this.value.replace(/\D+/g,'')"/><span class="f12 c6 mgl10">元</span>
        </div>
        <p class="f13 cred tl lh2" style="margin-left: 147px;"></p>
        <div class="baitiaoLineMoney" style="display:none">
            <p class="w100" style="background: #E7E7E7"></p>
            <p class="w100" style="background: #FFFFFF"></p>
        </div>
        <div <%if(CacheClass.getIntValue(obj.iscommon)==0){ %> style="display:none" <%} %> class="saveMoneyDiv jz clearfix of">
            <span class="fl f16 c3">余额</span>
            <p class="fr cff9933"><%=user.nowrmb %><span style="font-size: 19px"></span></p>
        </div>
        <div class="baitiaoLineMoney" style="display:none">
            <p class="w100" style="background: #E7E7E7"></p>
            <p class="w100" style="background: #FFFFFF"></p>
        </div>
        <div class="saveMoneyDiv jz clearfix of">
            <span class="fl f16 c3">可用额度</span>
            <p class="fr cff9933"><%=user.principlelrmb%><span style="font-size: 19px"></span></p>
        </div>
        <div class="baitiaoLineMoney" style="display:none">
            <p class="w100" style="background: #E7E7E7"></p>
            <p class="w100" style="background: #FFFFFF"></p>
        </div>
        <div class="saveMoneyDiv jz clearfix of" style="display:none">
            <span class="fl f16 c3">赠券类型</span>
            <%if(CacheClass.getIntValue(obj.type)==0){%>
            <p class="fr cff9933"><span class="f19">赠券不可亏损</span></p>
            <%}else{ %>
            <p class="fr cff9933"><span class="f19">赠券可亏损</span></p>
            <%} %>
        </div>
        <div class="baitiaoLineMoney" style="display:none">
            <p class="w100" style="background: #E7E7E7"></p>
            <p class="w100" style="background: #FFFFFF"></p>
        </div>
        
        <div class="saveMoneyDiv jz clearfix of" style="display:none">
            <span class="fl f16 c3">目前赠券比例</span>
            <p class="fr cff9933" ><span style="font-size: 24px" id="marate"><%if(CacheClass.getIntValue(user.vrnum)==0){%><%=obj.marate%><%}else{%>0<%} %></span><span style="font-size: 19px">%</span></p>
        </div>
        
        <div class="saveMoneyDiv jz clearfix of" style="display:none">
            <span class="fl f16 c3">目前(普通余额)赠券比例</span>
            <p class="fr cff9933" ><span style="font-size: 24px" id="commonrate"><%=obj.commonrate%></span><span style="font-size: 19px">%</span></p>
        </div>        
        
        <div class="baitiaoLineMoney">
            <p class="w100" style="background: #E7E7E7"></p>
            <p class="w100" style="background: #FFFFFF"></p>
        </div>
        <div class="saveMoneyDiv jz clearfix of">
            <span class="fl f16 c3">赠券金额(最高<%=maxcashrmb%>)</span>
            <p class="fr cff9933" id="payrmb">0<span style="font-size: 19px"></span></p>
        </div>
        <div class="baitiaoLineMoney">
            <p class="w100" style="background: #E7E7E7"></p>
            <p class="w100" style="background: #FFFFFF"></p>
        </div>
        <div class="saveMoneyDiv jz clearfix of">
            <span class="fl f16 c3">申请后增加可用金额</span>
            <p class="fr cff9933" id="addtotalrmb">0<span style="font-size: 19px"></span></p>
        </div>
        <div class="baitiaoLineMoney">
            <p class="w100" style="background: #E7E7E7"></p>
            <p class="w100" style="background: #FFFFFF"></p>
        </div>
        <div class="w100" style="margin-top: 25px;margin-bottom: 60px;">
            <p class="w100 f12 c9 tc" style="margin: 0;color: #f51010;">备注：赠券只有用户在第一次转入资金时才可获得；赠券只可用于市场交易，转出时赠券自动扣除。</p>
        </div>
    </section>
    
      <div class="w100 jz clearfix of" style="margin-top: 20px;margin-bottom: 30px;padding: 20px 5%;height: 164px;">
            <input id="agree" type="checkbox"  name="agree" value="agree" class="fl"  style="margin-left:35px;"><a href="pc/riskWarning.jsp" target="_blank" class="w100 f16 c9 fl blue" style="width: 50%;margin-left:21px;">查阅《风险揭示书》并同意</lable>
     </div>

    <input type="button" name="" value="确认转入" id="" onclick="Sub();" class="db jz bcblue cf f27 tc w100 cursor pa" style="left: 0;bottom:0;height: 63px;line-height: 63px;"/>
</div><!--container-->

<div id="loadingfDiv" class="loadingfDiv pf w100 h100 db">
    <div class="w100 h100">
        <img src="pc/images/loading.gif" class="db jz" style="margin-top: 40%;">
    </div>
</div><!--loadinfDiv-->


<script>

    $(window).on("load", function() {
        $("#zijinZhuanru", parent.document).click(function () {
            $("#zijinIframeDiv", parent.document).slideDown();
            $(".theme-popover-mask", parent.document).fadeIn();

        })
        $("#close-x").click(function () {
            $("#zijinIframeDiv", parent.document).slideUp();
            $(".theme-popover-mask", parent.document).fadeOut();

        })
        
        $('input:radio[name="moneyKind"]').change(function () {
           changermb();
        })
    })
    var maxcashrmb='<%=maxcashrmb%>';
    var money='<%=user.principlelrmb%>';
 	$().ready(function() {
 	    if(money*1.0<0) money=0;
 		else
 			$('#money').val(money); 
 			
		changermb();
	});

    function changermb()
    {
    	var rmbtypeVal=$("input[name='moneyKind']:checked").val();
    	var money =$.trim($('#money').val());
    	if(money== ""){return;}
    	
    	var rate=0;
    	if(rmbtypeVal==0)//普通
    	{
    		rate=$.trim($('#commonrate').html());
    	}
    	else
    	{
    		rate=$.trim($('#marate').html());
    	}
    	console.log(rate);
    	
    	var payrmbVal=rate*1.0*money/100.0;
    	
    	if(payrmbVal>maxcashrmb*1.0)
    	{
    		payrmbVal=maxcashrmb*1.0;
    	}
    	
    	var addtotalrmbVal=1.0*payrmbVal+1.0*money;
    	
    	console.log(payrmbVal);
    	console.log(addtotalrmbVal);
    	
    	 $('#payrmb').html(''+payrmbVal);
    	 $('#addtotalrmb').html(''+addtotalrmbVal);
    	
    	
    	
    }

    function Sub() {
    	 if ($('#agree').is(':checked') == false) {
	        alert("请查阅《风险提示》并同意");
	    	return false;
	    }
    
    
        var money =$.trim($('#money').val());
        if(money== ""){
            $('#money').parent('.saveMoneyDiv').next('p').text('你还未填写金额');
            return false;
        }else if(money*1.0== 0){
            $('#money').parent('.saveMoneyDiv').next('p').text('金额不能为0');
            return false;
        }
        else
        {
            $('#money').parent('.saveMoneyDiv').next('p').text(' ');
        }
        
       var vridVal=$.trim($('#vrid').val());
       var rmbtypeVal=$("input[name='moneyKind']:checked").val();

       $.ajax({
            url: "PlugServlet",
            data: ''+JSON.stringify({m:243,rmb:money,vrid:vridVal,rmbtype:rmbtypeVal}),
            type: 'post',
            dataType: 'json',
            contentType:"application/json;charset=utf-8",
            beforeSend: function () {
            },
            success: function (data) {
            	console.log(data);
              if(data['state']==1)
              {
                layer.alert(data.info);
              }
			  else
			  	layer.alert(data.info);
             },
            error: function (data) {
                layer.alert('网络忙，请重试');
            },
            complete: function () {
            }
        }); 
        
    }
</script>
</body>
</html>
